<template>
  <div class="count">
    <!-- 像普通属性一样使用计算属性 bigSum -->
    <h2>当前求和为{{ sum }},放大十倍后{{ bigSum }}</h2>
    <h3>
      欢迎来到{{ school }},坐落于{{ address }},学校名称大写{{ upperSchool }}
    </h3>
    <!-- v-model将选择框的选中值与 Vue 实例中的 n 数据属性进行绑定 -->
    <!-- 将收集到的数据尽量转为number -->
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add()">加</button>
    <button @click="reduce()">减</button>
  </div>
</template>

<script setup lang="ts" name="Count">
import { ref } from "vue";
import { useCountStort } from "@/store/count";
import { storeToRefs } from "pinia";

const countStore = useCountStort();
// const {sum,school,address} = toRefs(countStore)   //把countStore所有东西都变成impl 代价大
console.log(countStore);

const { sum, school, address, bigSum, upperSchool } = storeToRefs(countStore); //只会关注store的数据

//reactive中的ref被自动拆包  使用的时候不用.value
// let obj = reactive({
//   a: 1,
//   b: ref(3),
// });
// console.log(obj.a);
// console.log(obj.b);

let n = ref(1);

function add() {
  //第三种修改方式  actions
  countStore.increment(n.value);
}
function reduce() {
  countStore.sum -= n.value;
}
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}

select,
button {
  margin: 0 5px;
  height: 30px;
}
</style>
